package com.carsystems.controller;

import com.carsystems.mapper.StatueVltMapper;
import com.carsystems.pojo.StatueVlt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.soap.Addressing;
import java.util.List;

@RestController
public class StatueVltController {
    @Autowired
    private StatueVltMapper statueVltMapper;

    //查询全部的违规状态
    @GetMapping("/vltList")
    public List<StatueVlt> vltList(){
        List<StatueVlt> vlts = statueVltMapper.vltList();
        return vlts;
    }

    //按id查询单条违规状态
    @GetMapping("/selevlt")
    public  StatueVlt selevlt(int id){
       return   statueVltMapper.selectByPrimaryKey(id);
    }

    //增加一条违规状态
    @PostMapping("/addvlt")
    public String addvlt(@RequestBody StatueVlt statueVlt){
         statueVltMapper.addVlt(statueVlt);
         if (statueVlt != null){
             return "success";
         }else {
             return "fail";
         }
    }

    //修改一条违规状态
    @PutMapping("/updatevlt")
    public String updatevlt(@RequestBody StatueVlt statueVlt){
        int row =  statueVltMapper.updateVlt(statueVlt);
        statueVltMapper.selectByPrimaryKey(statueVlt.getId());
        if (row == 1){
            return "success";
        }else {
            return "fail";
        }
    }

    //删除一条违规状态
    @ResponseBody
    @DeleteMapping("/delevlt")
    public String delevlt(StatueVlt statueVlt){
       int row = statueVltMapper.deleVlt(statueVlt.getId());
        if (row == 1){
            return "success";
        }else {
            return "fail";
        }
    }
}
